
var setting = {
    check: {
        enable: true
    },
    data: {
        simpleData: {
            enable: true
        }
    },
    callback: {
        beforeCheck: beforeCheck,
        onCheck: onCheck
    }
};
var code, log, className = "dark";
function beforeCheck(treeId, treeNode) {
    className = (className === "dark" ? "":"dark");
    return (treeNode.doCheck !== false);
}
function onCheck(e, treeId, treeNode) {
    console.log(treeNode);
    var zTree = $.fn.zTree.getZTreeObj("treeDemo"),
        nodes = zTree.getCheckedNodes(true),
        v= "",
        arr = [];
    for (var i=0;i<nodes.length; i++) {
        v += nodes[i].name + ",";
        if(nodes[i].checked === true){
            arr.push(nodes[i].id);
        }
    }
    $('.layui-form-pane').append("<input type='hidden' name='menus' value="+arr+">");
}
function showCode(str) {
    if (!code) code = $("#code");
    code.empty();
    code.append("<li>"+str+"</li>");
}

$(document).ready(function(){
    $.ajax({
        url : ztree_url,
        type : 'get',
        dataType : 'json',
        success : function (result){
            $.fn.zTree.init($("#treeDemo"), setting, result);
        }
    });
});